package com.bbm.bbmanage.controller;


import com.bbm.bbmanage.entity.Category;
import com.bbm.bbmanage.entity.vo.ResponseResult;
import com.bbm.bbmanage.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Category)表控制层
 *
 * @author lionkliu
 * @since 2023-12-06 09:31:36
 */
@RestController
@RequestMapping("category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/list")
    public ResponseResult getAll() {
        List<Category> list = categoryService.list();
        return ResponseResult.okResult(list);
    }

    @GetMapping("/getCategory")
    public ResponseResult getCategory() {
        return categoryService.getCategory();
    }

    @GetMapping("/getCategoryLabelValue")
    public ResponseResult getCategoryLabelValue() {
        return categoryService.getCategoryLabelValue();
    }

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return categoryService.selectPage(pageNum, pageSize);
    }

    @GetMapping("{id}")
    public ResponseResult selectOne(@PathVariable Integer id) {
        return categoryService.selectOne(id);
    }

    @PostMapping
    public ResponseResult insert(@RequestBody Category category) {
        return categoryService.insertOne(category);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Category category) {
        return categoryService.updateOne(category);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return categoryService.deleteById(id);
    }

}
